//
//  CCFormViewController.m
//  CwinCar
//
//  Created by dlios on 15/10/15.
//  Copyright © 2015年 dlios. All rights reserved.
//

#import "CCFormViewController.h"
#import "AppDelegate.h"
@interface CCFormViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,pushWebDelegate,UICollectionViewDataSource,UICollectionViewDelegate,forumButtonDelegate>
{
    NSInteger count;
    NSArray *countArr;
    UIView *_bigView;
}
@property (nonatomic,strong)CCForumlunbotu *forumScro;
@end

@implementation CCFormViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self creatData];
    [self creatControlls];
    [self creatButtonScro];
    [self creatHotPageControll];
    [self creatCollectionCintroll];
    [self addHeader];
    [self releaseFoot];
    //    [self creatForumDate];
    self.page = 0;
    self.postListArray = [[NSMutableArray alloc]init];
    
    _elementArray = [[NSMutableArray alloc]init];
    _forumPicArray = [[NSMutableArray alloc]init];
}

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    
}
#pragma mark - 解析数据
- (void)creatData
{
    self.webLinkStrArray  = [[NSMutableArray alloc]init];
    self.shufflingArray = [[NSMutableArray alloc]init];
    self.CCForumTableArray = [[NSMutableArray alloc]init];
    self.focusLinckArray = [[NSMutableArray alloc]init];
    
    [AFNblock getdataWithString:@"http://mi.xcar.com.cn/interface/xcarapp/getSelectedPostList.php?limit=40&offset=0&ver=6.1.7" block:^(id block)
     {
         for (NSDictionary *focusPostDic in [block objectForKey:@"focusPost"]) {
             _forumModel = [CCForumModel modelWithDictionary:focusPostDic];
             [self.shufflingArray addObject:_forumModel];
             NSString *webString = [[NSString alloc]init];
             webString = [focusPostDic objectForKey:@"focusLink"];
             [self.focusLinckArray addObject:webString];
         }
         
         //解析tableview的数据
         for (NSDictionary *postListDic in [block objectForKey:@"postList"]) {
             
             _forumModel = [CCForumModel modelWithDictionary:postListDic];
             [self.CCForumTableArray addObject:_forumModel];
         }
         [self.CCForumTable reloadData];
         [_forumScro setData:_shufflingArray];
         
     }];
    //解析collectionView数据
    self.collectionArray = [[NSMutableArray alloc]init];
    NSString *str = @"http://a.xcar.com.cn/interface/6.0/getRecommendedForumList.php";
    [AFNblock getdataWithString:str block:^(id block) {
        
        for (NSDictionary *forums in [block objectForKey:@"forums"]) {
            
            _fourmButtonModel = [CCForumButtonModel modelWithDictionary:forums];
            [self.collectionArray addObject:_fourmButtonModel];
        }
        [self.forumCollectionView reloadData];
    }];
    
    
}
#pragma mark - 下拉加载
- (void)addHeader
{
    __block CCFormViewController *vc = self;
    [self.hotTableView addLegendHeaderWithRefreshingBlock:^{
        
        
        [vc AFDate:0];
        
    }];
    [self.hotTableView.header beginRefreshing];
}
#pragma mark - 上拉加载
-(void)releaseFoot
{
    __block CCFormViewController *vc = self;
    [self.hotTableView addLegendFooterWithRefreshingBlock:^{
        vc.page ++;
        [vc AFDate:vc.page];
    }];
}
#pragma mark -解析数据
-(void)AFDate:(NSInteger)number
{
    
    NSString *string = [NSString stringWithFormat:@"http://my.xcar.com.cn/app/6/getHotPostList.php?limit=20&offset=%ld&ver=6.1.7",number * 20];
    [AFNblock getdataWithString:string block:^(id block) {
        
        for (NSDictionary *postListDic in [block objectForKey:@"postList"]) {
            _hotModel = [CCForumHotModel modelWithDictionary:postListDic];
            [self.postListArray addObject:_hotModel];
        }
        [self.hotTableView.footer endRefreshing];
        [self.hotTableView.header endRefreshing];
        [self.hotTableView reloadData];
    }];
    
}
-(void)creatControlls
{
    self.backScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, mainScreen_Width, mainScree_Height -64 +15)];//mainScree_Height - 64 + 15
    [self.backScrollView setPagingEnabled:YES];
    [self.backScrollView setBounces:NO];
    [self.backScrollView showsHorizontalScrollIndicator];
    self.backScrollView.showsHorizontalScrollIndicator = NO;
    [self.backScrollView setContentSize:CGSizeMake(mainScreen_Width * 3, 0)];
    self.backScrollView.delegate = self;
    [self.view addSubview:self.backScrollView];
    //放置轮播图的UIView
    self.backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, mainScreen_Width, mainScree_Height / 3.705)];
    [self.backScrollView addSubview:self.backView];
    _forumScro = [[CCForumlunbotu alloc]initWithFrame:CGRectMake(0, 0, mainScreen_Width, mainScree_Height / 3.705)];
    [self.backView addSubview:_forumScro];
    _forumScro.delegatePush = self;
    self.CCForumTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, mainScreen_Width, mainScree_Height - 64 * suitableScreen_Height -49 * suitableScreen_Height) style:UITableViewStylePlain];
    self.CCForumTable.delegate = self;
    self.CCForumTable.dataSource = self;
    self.CCForumTable.tableHeaderView = self.backView;
    [self.backScrollView addSubview:self.CCForumTable];
    [self.CCForumTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
}

#pragma mark - 用协议实现button的点击方法  以实现web
- (void)lunbotu:(NSInteger)tag
{
    CCFormWebViewController *webPush = [[CCFormWebViewController alloc]init];
    webPush.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:webPush animated:YES];
    //    webPush.webStr = self.focusLinckArray[tag];
    webPush.webStr = self.focusLinckArray[_forumScro.page.currentPage];
    NSLog(@"%@",webPush.webStr);
}
#pragma mark - 创建UINavigationBar上button的实现方法
-(void)creatButtonScro
{
    self.buttonScView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, mainScree_Height / 66.7,mainScreen_Width / 1.923, mainScree_Height / 22.233)];
    self.buttonScView.delegate = self;
    [self.buttonScView setPagingEnabled:NO];
    [self.buttonScView showsHorizontalScrollIndicator];
    self.buttonScView.showsHorizontalScrollIndicator = NO;
    [self.buttonScView setContentSize:CGSizeMake(mainScreen_Width / 1.875, 0)];
    [self.navigationController.navigationBar addSubview:self.buttonScView];
    self.buttonArray = [[NSMutableArray alloc]init];
    NSArray *array =@[@"精选",@"热帖",@"论坛"];
    for (int i = 0; i < 3; i++) {
        UIButton *threeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [threeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [threeButton setTitle:[array objectAtIndex:i] forState:UIControlStateNormal];
        [threeButton setFrame:CGRectMake(mainScreen_Width / 37.5 + i * mainScreen_Width/ 6.8, 0, mainScreen_Width/ 7.8, mainScree_Height / 22.233)];
        [threeButton.titleLabel setFont:[UIFont systemFontOfSize:16.]];
        
        [threeButton addTarget:self action:@selector(threeClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.buttonArray addObject:threeButton];
        [self.buttonScView addSubview:threeButton];
    }
}
#pragma mark - 点击相应的button  跳转相应的页面
-(void)threeClick:(UIButton *)button
{
    if (self.buttonArray[0] == button)
    {
        [self.backScrollView setContentOffset:CGPointMake(mainScreen_Width * 0, 0)];
    }
    if (self.buttonArray[1] == button)
    {
        [self.backScrollView setContentOffset:CGPointMake(mainScreen_Width * 1,0) animated:YES];
    }
    if (self.buttonArray[2] == button)
    {
        [self.backScrollView setContentOffset:CGPointMake(mainScreen_Width * 2,0) animated:YES];
    }
    [self.CCForumTable reloadData];
}
#pragma mark 背景scrollView关联点击按钮
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == self.backScrollView)
    {
        for (int i = 0; i < 3; i++)
        {
            if (self.backScrollView.contentOffset.x == mainScreen_Width * i)
            {
                [self.buttonArray[i] setFont:[UIFont systemFontOfSize:16.]];
                if (i > 1)
                {
                    [self.buttonScView setContentOffset:CGPointMake(58 * (i - 2), 0)];
                }
            }else
            {
                [self.buttonArray[i] setFont:[UIFont systemFontOfSize:14.]];
            }
        }
    }
}

#pragma mark tableView协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    if (tableView == _CCForumTable) {
        return self.CCForumTableArray.count;
    }
    if (tableView == _pictrueTableView) {
        NSArray *array = [NSArray arrayWithArray:_separeteArray[section]];
        return array.count;
    }else if (tableView == _pictrueForumTableView)
    {
        return count;
    }
    
    else
    {
        return  self.postListArray.count;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _CCForumTable) {
        
        return mainScree_Height / 6.67;
    }
    if (tableView == _pictrueTableView) {
        return 60 * suitableScreen_Height;
    }else if (tableView == _pictrueForumTableView)
    {
        return 60 * suitableScreen_Height;
    }
    
    else
    {
        return mainScree_Height / 9.528;
    }
    
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _CCForumTable) {
        
        
        static NSString *cellId = @"cell";
        CCForumTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[CCForumTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
        }
        _forumModel = [self.CCForumTableArray objectAtIndex:indexPath.row];
        [cell setData:_forumModel];
        
        return cell;
    }else if (tableView == _pictrueTableView)
    {
        static NSString *picCellId = @"picCell";
        CCForumPictureTableViewCell *picCell = [tableView dequeueReusableCellWithIdentifier:picCellId];
        if (!picCell) {
            picCell = [[CCForumPictureTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:picCellId];
        }
        NSArray *array = [_separeteArray objectAtIndex:indexPath.section];
        _brandsModel = [array objectAtIndex:indexPath.row];
        [picCell setData:_brandsModel];
        [picCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return picCell;
    }else if (tableView == _pictrueForumTableView)
    {
        //论坛点击方法
        static NSString *picForumCellId= @"picForumCell";
        CCFourmPicturePushTableViewCell *picForumCell = [tableView dequeueReusableCellWithIdentifier:picForumCellId];
        if (!picForumCell) {
            picForumCell = [[CCFourmPicturePushTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:picForumCellId];
        }
        
        [picForumCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        _forumsModel = [countArr objectAtIndex:indexPath.row];
        [picForumCell setDataModel:_forumsModel];
        return picForumCell;
    }
    else
    {
        static NSString *hotCellId = @"CCForumHotTalkingViewCell";
        CCForumHotTalkViewCell *CCForumHotTalkingViewCell = [tableView dequeueReusableCellWithIdentifier:hotCellId];
        if (!CCForumHotTalkingViewCell) {
            CCForumHotTalkingViewCell  = [[CCForumHotTalkViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:hotCellId];
        }
        _hotModel = [_postListArray objectAtIndex:indexPath.row];
        [CCForumHotTalkingViewCell setData:_hotModel];
        CCForumHotTalkingViewCell.picView.hidden = YES;
        if (CCForumHotTalkingViewCell.isType == YES) {
            CCForumHotTalkingViewCell.picView.hidden = NO;
        }
        return CCForumHotTalkingViewCell;
    }
}
#pragma mark - section的相关属性
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (tableView == _pictrueTableView) {
        
        CCForumPictureModel *model = [_elementArray objectAtIndex:section];
        if (model.letter != nil) {
            
            return model.letter;
        }else
        {
            return model.categoryName;
        }
    }
    return nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView == _pictrueTableView) {
        return _elementArray.count;
    }
    return 1;
}
- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    if (tableView == _pictrueTableView) {
        return _letterArray;
    }
    return nil;
}

#pragma mark- tableview的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _CCForumTable) {
        CCFormWebViewController *webVC = [[CCFormWebViewController alloc]init];
        webVC.hidesBottomBarWhenPushed = YES;
        CCForumModel *model = [self.CCForumTableArray objectAtIndex:indexPath.row];
        webVC.webStr = model.postLink;
        [self.navigationController pushViewController:webVC animated:YES];
    }else if (tableView == _hotTableView)
    {
        CCFormWebViewController *webHotVC = [[CCFormWebViewController alloc]init];
        webHotVC.hidesBottomBarWhenPushed = YES;
        CCForumHotModel *model = [self.postListArray objectAtIndex:indexPath.row];
        webHotVC.webStr = model.postLink;
        [self.navigationController pushViewController:webHotVC animated:YES];
    }
    if (tableView == _pictrueTableView) {
        [self.view bringSubviewToFront:self.pictrueForumTableView];
        [UIView animateWithDuration:0.3 animations:^{
            _pictrueForumTableView.frame =  CGRectMake(mainScreen_Width  -320 * suitableScreen_Width, 0, 320 * suitableScreen_Width, mainScree_Height - 113);
            
        }];
        if (_forumPicArray != nil) {
            if (self.pictrueForumTableView.hidden == YES) {
                self.pictrueForumTableView.hidden = NO;
            }
            
            NSArray *arr = [_forumPicArray objectAtIndex:indexPath.section];
            countArr = [arr objectAtIndex:indexPath.row];
            count = countArr.count;
            
        }else
        {
            CCForumPushViewController *pushVC = [[CCForumPushViewController alloc]init];
            
            _brandsModel = [[_separeteArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
            pushVC.forumId = _brandsModel.forumId;
            pushVC.forumName = _brandsModel.forumName;
            pushVC.hidesBottomBarWhenPushed = YES;//隐藏tabbar 当pushVC pop的时候 系统会自动操作 tabbar的显现
            [self.navigationController pushViewController:pushVC animated:YES];
        }
        
        [_pictrueForumTableView reloadData];
    }
    if (tableView == _pictrueForumTableView) {
        _forumsModel = [countArr objectAtIndex:indexPath.row];
        
        CCForumPushViewController *pushVC = [[CCForumPushViewController alloc]init];
        
        //        _forumsModel = [[_separeteArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
        pushVC.forumId = _forumsModel.forumId;
        pushVC.forumName = _forumsModel.forumName;
        pushVC.hidesBottomBarWhenPushed = YES;//隐藏tabbar 当pushVC pop的时候 系统会自动操作 tabbar的显现
        [self.navigationController pushViewController:pushVC animated:YES];
    }
}
#pragma mark - 创建热帖
-(void)creatHotPageControll
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(mainScreen_Width, 0, mainScreen_Width, 45 * suitableScreen_Height)];
    [self.backScrollView addSubview:view];
    
    _picImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, mainScreen_Width, 45 * suitableScreen_Height )];
    [_picImg setImage:[UIImage imageNamed:@"lanse"]];
    _picImg.userInteractionEnabled = YES;
    [view addSubview:_picImg];
    
    UILabel *keyLabel = [[UILabel alloc]initWithFrame:CGRectMake(15 * suitableScreen_Width, 5 * suitableScreen_Height, mainScreen_Width, 35 * suitableScreen_Height)];
    [keyLabel setText:@"    24 小 时 热 帖"];
    [keyLabel setFont:[UIFont systemFontOfSize:18.]];
    [keyLabel setTextColor:[UIColor whiteColor]];
    [_picImg addSubview:keyLabel];
    
    self.hotTableView = [[UITableView alloc]initWithFrame:CGRectMake(mainScreen_Width, 0, mainScreen_Width, mainScree_Height - 64 - 50 ) style:UITableViewStylePlain];
    self.hotTableView.delegate = self;
    self.hotTableView.dataSource = self;
    [self.backScrollView addSubview:self.hotTableView];
    self.hotTableView.tableHeaderView = view;
    
}
#pragma mark - 创建论坛
-(void)creatCollectionCintroll
{
    self.forumButton = [[ForumButton alloc]initWithFrame:CGRectMake(mainScreen_Width * 2, 10 * suitableScreen_Height, mainScreen_Width, 125 * suitableScreen_Height)];
    self.forumButton.backgroundColor = [UIColor whiteColor];
    [self.backScrollView addSubview:self.forumButton];
    self.imgeView =[[UIImageView alloc]initWithFrame:CGRectMake(mainScreen_Width * 2, 135 * suitableScreen_Height, mainScreen_Width, 30 * suitableScreen_Height)];
    self.forumButton.delegate = self;
    [self.imgeView setImage:[UIImage imageNamed:@"lanse"]];
    [self.backScrollView addSubview:self.imgeView];
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(20 * suitableScreen_Width, 5 * suitableScreen_Height, 100 *suitableScreen_Width, 20 *suitableScreen_Height)];
    lable.text = @"推荐论坛";
    lable.textColor = [UIColor whiteColor];
    [self.imgeView addSubview:lable];
    self.backScrollView.backgroundColor = [UIColor colorWithWhite:0.965 alpha:1.000];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(170 * suitableScreen_Width, 60 * suitableScreen_Height);
    flowLayout.minimumInteritemSpacing = 1;
    flowLayout.minimumLineSpacing = 1;
    flowLayout.sectionInset = UIEdgeInsetsMake(mainScreen_Width/ 18.75, mainScree_Height / 33.35, mainScreen_Width / 18.75, mainScree_Height / 133.4);
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.forumCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(mainScreen_Width * 2, 165 * suitableScreen_Height, mainScreen_Width, mainScree_Height - 64*suitableScreen_Height - 49*suitableScreen_Height) collectionViewLayout:flowLayout];
    [self.forumCollectionView setBackgroundColor:[UIColor whiteColor]];
    self.forumCollectionView.delegate = self;
    self.forumCollectionView.dataSource = self;
    [self.backScrollView addSubview:self.forumCollectionView];
    self.forumCollectionView.backgroundColor = [UIColor colorWithWhite:0.965 alpha:1.000];
    [self.forumCollectionView registerClass:[CCForumCollectionViewCell   class] forCellWithReuseIdentifier:@"cellId"];
    
}
- (void)creatPictureTable
{
    //创建论坛点击的tableview
    _pictrueForumTableView = [[UITableView alloc]initWithFrame:CGRectMake(mainScreen_Width, 0, mainScreen_Width / 2 - 40 * suitableScreen_Width, mainScree_Height) style:UITableViewStylePlain];
    _pictrueForumTableView.delegate = self;
    _pictrueForumTableView.dataSource = self;
    [_pictrueForumTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:_pictrueForumTableView];
    
    UISwipeGestureRecognizer *swipePush = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(pushForumSwipe)];
    [_pictrueForumTableView addGestureRecognizer:swipePush];
}
-(void)creatTable
{
    
    _pictrueTableView = [[UITableView alloc]initWithFrame:CGRectMake(mainScreen_Width , 0,mainScreen_Width/2 - 40 * suitableScreen_Width, mainScree_Height) style:UITableViewStylePlain];
    _pictrueTableView.delegate = self;
    _pictrueTableView.dataSource = self;
    [self.view addSubview:_pictrueTableView];
    _pictrueTableView.sectionIndexColor = [UIColor grayColor];
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(pushSwipe)];
    [_pictrueTableView addGestureRecognizer:swipe];
}
#pragma mark -论坛其他两个数据解析
- (void)creatForumDate:(NSInteger)number
{
    _elementArray = [[NSMutableArray alloc]init];
    _letterArray = [[NSMutableArray alloc]init];
    NSString *picStr =[NSString stringWithFormat:@"http://mi.xcar.com.cn/interface/xcarapp/getForumList.php?type=%ld&ver=6.2.2",number];
    [AFNblock getdataWithString:picStr block:^(id block) {
        for (NSDictionary *categoryNameDic in [block objectForKey:@"categories"]) {
            
            _letterModel = [CCForumPictureModel modelWithDictionary:categoryNameDic];
            NSString *str = _letterModel.categoryName;
            [_letterArray addObject:str];
            [_elementArray addObject:_letterModel];
        }
        
        for (NSDictionary *letterDic in [block objectForKey:@"categories"]) {
            _brandsArray = [[NSMutableArray alloc]init];
            for (NSDictionary *brandsDic in [letterDic objectForKey:@"forums"]) {
                
                _brandsModel = [CCForumPictureModel modelWithDictionary:brandsDic];
                
                [_brandsArray addObject:_brandsModel];
                
            }
            [_separeteArray addObject:_brandsArray];
            
        }
        
        [_pictrueTableView reloadData];
    }];
    
    
}
- (void)creatDatePush
{
    //解析论坛图片点击方法的数据
    
    _letterArray = [[NSMutableArray alloc]init];
    _elementArray = [[NSMutableArray alloc]init];
    NSString *picStr = @"http://mi.xcar.com.cn/interface/xcarapp/getForumList.php?type=0&ver=6.2.2";
    [AFNblock getdataWithString:picStr block:^(id block) {
        for (NSDictionary *letterDic in [block objectForKey:@"letters"]) {
            _letterModel = [CCForumPictureModel modelWithDictionary:letterDic];
            NSString *str = _letterModel.letter;
            [_letterArray addObject:str];
            [_elementArray addObject:_letterModel];
        }
        
        for (NSDictionary *letterDic in [block objectForKey:@"letters"]) {
            _brandsArray = [[NSMutableArray alloc]init];
            for (NSDictionary *brandsDic in [letterDic objectForKey:@"brands"]) {
                
                _brandsModel = [CCForumPictureModel modelWithDictionary:brandsDic];
                
                [_brandsArray addObject:_brandsModel];
            }
            [_separeteArray addObject:_brandsArray];
            
        }
        [_pictrueTableView reloadData];
        
        
        
        //解析点击论坛的数据
        for (NSDictionary *letterDic in [block objectForKey:@"letters"]) {
            _forumsArray = [[NSMutableArray alloc]init];
            
            for (NSDictionary *brandsDic in [letterDic objectForKey:@"brands"]) {
                _secondArray = [[NSMutableArray alloc]init];
                
                for (NSDictionary *forumsDic in [brandsDic objectForKey:@"forums"]) {
                    
                    _forumsModel = [CCForumPictureModel modelWithDictionary:forumsDic];
                    [_secondArray addObject:_forumsModel];
                    
                }
                [_forumsArray addObject:_secondArray];
                
            }
            [_forumPicArray addObject:_forumsArray];
            
        }
        [_pictrueForumTableView reloadData];
        
        
        
    }];
}
#pragma mark- 论坛封装实现的协议方法
- (void)touch:(UIButton *)button
{
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(picturePressGesture:)];
    tapGesture.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tapGesture];
    if (button.tag == 0) {
        
        if (self.pictrueTableView == nil) {
            [self creatTable];
            [self creatPictureTable];
            self.forumPicArray = [NSMutableArray array];
            self.separeteArray = [NSMutableArray array];
            [self creatDatePush];
            
        }
        
    }else if (button.tag == 1)
    {
        if (self.pictrueTableView == nil) {
            self.separeteArray = [NSMutableArray array];
            _forumPicArray  = nil;
            
            [self creatForumDate:1];
            [self creatTable];
        }
    }
    
    if (button.tag == 2) {
        if (self.pictrueTableView == nil) {
            _forumPicArray  = nil;
            self.separeteArray = [NSMutableArray array];
            [self creatForumDate:2];
            [self creatTable];
        }
    }
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionTransitionCurlUp animations:^{
        self.pictrueTableView.frame = CGRectMake(mainScreen_Width  -320 * suitableScreen_Width, 0, 320 * suitableScreen_Width, mainScree_Height - 113);
    } completion:nil];
    
}
#pragma mark -空白处的手势方法
- (void)picturePressGesture:(UITapGestureRecognizer *)sender
{
    CGPoint point = [sender locationInView:self.pictrueTableView];
    if (point.x<self.pictrueTableView.frame.origin.x && point.y > self.forumButton.frame.size.height) {
        
        [self.view removeGestureRecognizer:sender];
        [self pushSwipe];
        
    }
}
#pragma mark - 添加手势
- (void)pushSwipe
{
    //    __weak typeof(self)weakSelf = self;
    
    [UIView animateWithDuration:0.3 animations:^{
        //        weakSelf.pictrueTableView.delegate = nil;
        //        weakSelf.pictrueTableView.dataSource = nil;
        //        [weakSelf.separeteArray removeAllObjects];
        //        [weakSelf.elementArray removeAllObjects];
        //
        //        [weakSelf.pictrueTableView removeFromSuperview];
        //        [_separeteArray removeAllObjects];
        //        [_elementArray removeAllObjects];
        [self.pictrueTableView removeFromSuperview];
        self.pictrueTableView = nil;
        [self.pictrueForumTableView removeFromSuperview];
        self.pictrueForumTableView = nil;
        
        
    }];
}
-(void)pushForumSwipe
{
    [UIView animateWithDuration:0.3 animations:^{
        
        //        [self.pictrueTableView removeFromSuperview];
        //        self.pictrueTableView = nil;
        //        [self.pictrueForumTableView removeFromSuperview];
        self.pictrueForumTableView.hidden = YES;
        
    }];
}
#pragma mark - collectionView协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.collectionArray.count;
}
#pragma mark - 点击方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    CCForumPushViewController *pushVC = [[CCForumPushViewController alloc]init];
    _collectionModel = [_collectionArray objectAtIndex:indexPath.row];
    pushVC.forumId = _collectionModel.forumId;
    pushVC.forumName = _collectionModel.forumName;
    pushVC.hidesBottomBarWhenPushed = YES;//隐藏tabbar 当pushVC pop的时候 系统会自动操作 tabbar的显现
    [self.navigationController pushViewController:pushVC animated:YES];
    
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    _fourmButtonModel = self.collectionArray[indexPath.row];
    CCForumCollectionViewCell *forumCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
    [forumCell.nameLab setText:_fourmButtonModel.forumName];
    return forumCell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
